package com.okwanshiwu.payment.common;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 支付通用工具类
 *
 * @author
 * @create 2017-08-01 14:52
 **/
public class CommonPayUtil {

	//length表示生成字符串的长度
	public static String getRandomString(int length) {
		String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
		Random random = new Random();
		StringBuffer sb = new StringBuffer();
		int number = 0;
		for (int i = 0; i < length; i++) {
			number = random.nextInt(base.length());
			sb.append(base.charAt(number));
		}
		return sb.toString();
	}

	/*
	 * 生成当前时间
	 */
	public static String timeStart(){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		return sdf.format(new Date());
	}

	/*
	 * 订单开始交易的时间
	 */
	public static String timeExpire(){
		Calendar now = Calendar.getInstance();
		now.add(Calendar.MINUTE,60);
		SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
		return df.format(now.getTimeInMillis());
	}

}
